/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketManager.ejb;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import ticketManager.model.Product;

/**
 *
 * @author Administrator
 */
@Stateless
public class ProductDAO {
    @PersistenceContext
    EntityManager em;
    
    public Product createProduct(String title)
    {
        Product product = new Product(title);
        em.persist(product);
        return product;
    }
    
    public List<Product> getAllProduct()
    {
        List<Product> pro_all = em.createQuery("select p from Product p").getResultList();
        return pro_all;
    }
    
    public Product getProductByTitle(String title)
    {
        Product p = (Product)em.createQuery("select p from Product p where p.title=:title").setParameter("title", title).getSingleResult();
        return p;
    }
}
